<?php

class User {

    private $mId;
    private $mUsername;
    private $mEmail;
    private $mName;
    private $mPassword;
    private $mGroup;
    private $mIsEnabled;
    private $mLastLogin;

    public function setId($value){
        $this->mId = $value;
    }
    
    public function getId(){
        return $this->mId;
    }

    public function setUsername($value){
        $this->mUsername = $value;
    }

    public function getUsername(){
        return $this->mUsername;
    }
    
    public function setEmail($value){
        $this->mEmail = $value;
    }
    
    public function getEmail(){
        return $this->mEmail;
    }
    
    public function setName($value){
        $this->mName = $value;
    }
    
    public function getName(){
        return $this->mName;
    }
    
    public function setHashedPassword($value){
        $this->mPassword = $value;
    }
    public function setPassword($value){
        $this->mPassword = Hash::make($value);
    }
    
    public function getPassword(){
        return $this->mPassword;
    }

    public function setGroup($value){
        $this->mGroup = $value;
    }

    public function getGroup(){
         if (($this->mGroup != null) && (!$this->mGroup->IsLoaded())) {
            $GroupDao = new UserGroupDao();
            $this->mGroup = $GroupDao->getObject($this->mGroup->getId());
            if ($this->mGroup != null) $this->mGroup->setIsLoaded(true);
            }
        return $this->mGroup;
    }

    public function setIsEnabled($value){
        $this->mIsEnabled = $value;
    }
    
    public function getIsEnabled(){
        return $this->mIsEnabled;
    }
      
    public function setLastLogin($value){
        $this->mLastLogin = $value;
    }
    
    public function getLastLogin(){
        return $this->mLastLogin;
    }
    
    public function setIsLoaded($value){
        $this->mIsLoaded = $value;
    }
    
    public function IsLoaded(){
        return $this->mIsLoaded;
    }
    
    public function toArray() {
        $data = array(
                'id' => $this->mId,
                'username' => $this->mUsername,
                'name' => $this->mName,
                'email' => $this->mEmail,
                'password' => $this->mPassword,
                'group_id' => $this->getGroup()->getId(),
                'is_enabled' => $this->mIsEnabled
        );

        return $data;
    }
}
